#!/bin/sh
#
# Install any pre-provisioned Proffiles or Resoures and initialization file
#

VPN_ETCDIR=/etc/opt/cisco-vpnclient
OLD_ETCDIR=/etc/CiscoSystemsVPNClient
VOLUMEDIR=`df -k "$1" | grep dev | awk '{print $6, $7, $8, $9 }' | sed 's/^[ ^t]*//;s/[ ^]*$//'`



# cleanup after older versions of the client.

mkdir -p ${VPN_ETCDIR}
chown root:wheel /etc/opt

if [ -d "${OLD_ETCDIR}" -a ! -h "${OLD_ETCDIR}" ]; then
    mv ${OLD_ETCDIR}/* ${VPN_ETCDIR}
    rm -rf ${OLD_ETCDIR}
fi

ln -s ${VPN_ETCDIR} ${OLD_ETCDIR}

# if our preflight detected and saved a vpnclient.ini file, we restore
# that file now.

if [ -f ${VPN_ETCDIR}/vpnclient.ini.existing ]; then
    mv ${VPN_ETCDIR}/vpnclient.ini.existing ${VPN_ETCDIR}/vpnclient.ini
fi

# Install the pre-provisioned initialization file, if it exists.
cp -f "${VOLUMEDIR}/vpnclient.ini" ${VPN_ETCDIR}

# Install localized VPN Client profiles.
mkdir -p ${VPN_ETCDIR}/Profiles
for filename in "${VOLUMEDIR}"/Profiles/*
do
    cp -f "$filename" ${VPN_ETCDIR}/Profiles
done

# Install localized VPN Client resources
mkdir -p ${VPN_ETCDIR}/Certificates
mkdir -p ${VPN_ETCDIR}/Resources
mkdir -p ${VPN_ETCDIR}/Logs

for filename in "${VOLUMEDIR}"/Resources/*
do
    cp -f "$filename" ${VPN_ETCDIR}/Resources
done

# Set directory permissions
#XXX adjust permissions
chmod 0777 ${VPN_ETCDIR}
chmod 0777 ${VPN_ETCDIR}/Certificates
chmod 0777 ${VPN_ETCDIR}/Profiles
chmod 0777 ${VPN_ETCDIR}/Resources
chmod 0777 ${VPN_ETCDIR}/Logs

# Set file permissions
#XXX adjust permissions
chmod 0666 ${VPN_ETCDIR}/vpnclient.ini
chmod 0666 ${VPN_ETCDIR}/Profiles/*.pcf
chmod 0666 ${VPN_ETCDIR}/Resources/*.png

# now set the ownership, this must be root:wheel

chown -R root:wheel ${VPN_ETCDIR}

# This script is ALWAYS successful
exit 0;
